/* $Id : shopping_flow.js 4865 2007-01-31 14:04:10Z paulgao $ */

var selectedShipping = null;
var selectedPayment  = null;
var selectedPack     = null;
var selectedCard     = null;
var selectedSurplus  = '';
var selectedBonus    = 0;
var selectedIntegral = 0;
var selectedOOS      = null;
var alertedSurplus   = false;

var groupBuyShipping = null;
var groupBuyPayment  = null;

var confirmAddress = false;
var confirmShippingTime = false;
var confirmCoupon = false;
var confirmInvoice = false;
var confirmPayment = false;
var isAnoymous = false;
var disableInvoice = 0;

//wwzedit 购物车提交提示登录
function flowcartCheckLogin(){	
	$("#flowcartCheckLogin").val("1");
	$("#flowLoginTip").show();
}

//wwzedit 购物车登录跳转到结算
$(function(){
	$("#flowcartLoginImg").click(function(){
		$("#flowLoginTip").hide();
		login_a();
	})		   
})

//wwzedit 购物车登录提示关闭按钮
$(function(){
	$("#flowLoginTipClose").click(function(){
		$("#flowLoginTip").hide();
	})		   
})

//wwzedit 购物车删除确定
function flowcartDeleteConfirm(rec_id){	
	$("#flowcartDeleteConfirm").show();
	var val = rec_id;
	
	$("#flowcartDeleteConfirmYes").click(function(){
		window.location.href='flow.php?step=drop_goods&id='+val;
		$("#flowcartDeleteConfirm").hide();
	})
	$("#flowcartDeleteConfirmNo").click(function(){
		$("#flowcartDeleteConfirm").hide();
	})
	$("#flowcartDeleteConfirmClose").click(function(){
		$("#flowcartDeleteConfirm").hide();
	})	
	
}

/* *
 * 改变配送方式
 */
function selectShipping(obj)
{
  if (selectedShipping == obj)
  {
    return;
  }
  else
  {
    selectedShipping = obj;
  }

  var supportCod = obj.attributes['supportCod'].value + 0;
  var theForm = obj.form;

  for (i = 0; i < theForm.elements.length; i ++ )
  {
    if (theForm.elements[i].name == 'payment' && theForm.elements[i].attributes['isCod'].value == '1')
    {
      if (supportCod == 0)
      {
        theForm.elements[i].checked = false;
        theForm.elements[i].disabled = true;
      }
      else
      {
        theForm.elements[i].disabled = false;
      }
    }
  }


  var now = new Date();
  Ajax.call('flow.php?step=select_shipping', 'shipping=' + obj.value, orderShippingSelectedResponse, 'GET', 'JSON');
}

/**
 *
 */
function orderShippingSelectedResponse(result)
{
  if (result.need_insure)
  {
    try
    {
      document.getElementById('ECS_NEEDINSURE').checked = true;
    }
    catch (ex)
    {
      alert(ex.message);
    }
  }

  try
  {
    if (document.getElementById('ECS_CODFEE') != undefined)
    {
      document.getElementById('ECS_CODFEE').innerHTML = result.cod_fee;
    }
  }
  catch (ex)
  {
    alert(ex.message);
  }

  orderSelectedResponse(result);
}

/* *
 * 改变支付方式
 */
function selectPayment(obj)
{
  if (selectedPayment == obj)
  {
    return;
  }
  else
  {
    selectedPayment = obj;
  }

  Ajax.call('flow.php?step=select_payment', 'payment=' + obj.value, orderSelectedResponse, 'GET', 'JSON');
}
/* *
 * 团购购物流程 --> 改变配送方式
 */
function handleGroupBuyShipping(obj)
{
  if (groupBuyShipping == obj)
  {
    return;
  }
  else
  {
    groupBuyShipping = obj;
  }

  var supportCod = obj.attributes['supportCod'].value + 0;
  var theForm = obj.form;

  for (i = 0; i < theForm.elements.length; i ++ )
  {
    if (theForm.elements[i].name == 'payment' && theForm.elements[i].attributes['isCod'].value == '1')
    {
      if (supportCod == 0)
      {
        theForm.elements[i].checked = false;
        theForm.elements[i].disabled = true;
      }
      else
      {
        theForm.elements[i].disabled = false;
      }
    }
  }

  if (obj.attributes['insure'].value + 0 == 0)
  {
    document.getElementById('ECS_NEEDINSURE').checked = false;
    document.getElementById('ECS_NEEDINSURE').disabled = true;
  }
  else
  {
    document.getElementById('ECS_NEEDINSURE').checked = false;
    document.getElementById('ECS_NEEDINSURE').disabled = false;
  }

  Ajax.call('group_buy.php?act=select_shipping', 'shipping=' + obj.value, orderSelectedResponse, 'GET');
}

/* *
 * 团购购物流程 --> 改变支付方式
 */
function handleGroupBuyPayment(obj)
{
  if (groupBuyPayment == obj)
  {
    return;
  }
  else
  {
    groupBuyPayment = obj;
  }

  Ajax.call('group_buy.php?act=select_payment', 'payment=' + obj.value, orderSelectedResponse, 'GET');
}

/* *
 * 改变商品包装
 */
function selectPack(obj)
{
  if (selectedPack == obj)
  {
    return;
  }
  else
  {
    selectedPack = obj;
  }

  Ajax.call('flow.php?step=select_pack', 'pack=' + obj.value, orderSelectedResponse, 'GET', 'JSON');
}

/* *
 * 改变祝福贺卡
 */
function selectCard(obj)
{
  if (selectedCard == obj)
  {
    return;
  }
  else
  {
    selectedCard = obj;
  }

  Ajax.call('flow.php?step=select_card', 'card=' + obj.value, orderSelectedResponse, 'GET', 'JSON');
}

/* *
 * 选定了配送保价
 */
function selectInsure(needInsure)
{
  needInsure = needInsure ? 1 : 0;

  Ajax.call('flow.php?step=select_insure', 'insure=' + needInsure, orderSelectedResponse, 'GET', 'JSON');
}

/* *
 * 团购购物流程 --> 选定了配送保价
 */
function handleGroupBuyInsure(needInsure)
{
  needInsure = needInsure ? 1 : 0;

  Ajax.call('group_buy.php?act=select_insure', 'insure=' + needInsure, orderSelectedResponse, 'GET', 'JSON');
}

/* *
 * 回调函数
 */
// function orderSelectedResponse(result)
// {
//   if (result.error)
//   {
//     alert(result.error);
//     location.href = './';
//   }

//   try
//   {
//     var layer = document.getElementById("ECS_ORDERTOTAL");
    
//     layer.innerHTML = (typeof result == "object") ? result.content : result;

//     if (result.payment != undefined)
//     {
//       var surplusObj = document.forms['theForm'].elements['surplus'];
//       if (surplusObj != undefined)
//       {
//         surplusObj.disabled = result.pay_code == 'balance';
//       }
//     }
//     if(result.disableInvoice != undefined){      
//       if(result.disableInvoice == 1){
//         $(".fapiaoxinxi").hide();
//         $("input[name='need_invoice'],input[name='inv_need_addr']").each(function () {
//             if ($(this).val() == "0" ) {
//                 $(this).prop("checked",true);
//             }else{
//               $(this).prop("checked",false);
//             }
//         });
//         $("#inv_payee").val('');

//         $("#invoiceInfoText").text('因使用礼品卡/积分全额支付,无法开具发票').attr('status','1').show();

//       }else{
        
//         if($(".shouqi").is(":hidden")){
//           $(".fapiao_xinxi").find('.xiugai_zhifuxinxi').show();
//           $("#invoiceInfoText").text('不需要发票').attr('status','0').show()
//         }
        
//       }
      
//     }
//   }
//   catch (ex) { }
// }
function orderSelectedResponse(result)
{
  if (result.error)
  {
    alert(result.error);
    location.href = './';
  }

  try
  {
    var layer = document.getElementById("ECS_ORDERTOTAL");
    
    layer.innerHTML = (typeof result == "object") ? result.content : result;

    if (result.payment != undefined)
    {
      var surplusObj = document.forms['theForm'].elements['surplus'];
      if (surplusObj != undefined)
      {
        surplusObj.disabled = result.pay_code == 'balance';
      }
    }
    if(result.disableInvoice != undefined){
      disableInvoice = result.disableInvoice;
      if(disableInvoice == 1){
        $(".fapiao_xinxi").find('.xiugai_zhifuxinxi').prev().attr("class","peisong_title_name_span_yes").end().hide();
        $("#inv_payee").val('');
        $(".fapiaoxinxi").hide();
        $("#invoiceInfoText").text('因使用礼品卡/积分全额支付,无法开具发票').show();     
        $("#invoiceInfoText").attr('origin','因使用礼品卡/积分全额支付,无法开具发票');
        $("input[name='need_invoice'],input[name='inv_need_addr']").each(function () {
            if ($(this).val() == "0" ) {
                $(this).prop("checked",true);
            }else{
              $(this).prop("checked",false);
            }
        });


      }else{
        
        if($(".shouqi").is(":hidden")){
          $(".fapiao_xinxi").find('.xiugai_zhifuxinxi').show();
          $("#invoiceInfoText").text('不需要发票').show()
          $("#invoiceInfoText").attr('origin','请先确认优惠信息');
        }
        
      }
      
    }

    if (result.bonus != undefined) {
        if (parseFloat(result.bonus) > 0) {
            $('#bonusAmount').text('使用优惠券:'+result.bonus_formated+' ').addClass('juankazhekou_names');
            
        }else{
            $('#bonusAmount').text('').removeClass('juankazhekou_names');
        }
    }

    if(result.giftCardAmount != undefined){
        if (parseFloat(result.giftCardAmount) > 0) {

            $("#giftCardAmount").text('使用礼品卡:￥'+result.giftCardAmount+' ').addClass('juankazhekou_names');

        }else{
            $('#giftCardAmount').text('').removeClass('juankazhekou_names');    
        }        
    }


    if (result.integral != undefined) {
        if (parseFloat(result.integral) > 0) {
            $('#integralAmount').text('使用'+result.integral+'积分抵消'+result.integral_formated).addClass('juankazhekou_names');
            
        }else{
            $('#integralAmount').text('').removeClass('juankazhekou_names');
        }
    }
  }
  catch (ex) { }
}
/* *
 * 改变余额
 */
function changeSurplus(val)
{
  if (selectedSurplus == val)
  {
    return;
  }
  else
  {
    selectedSurplus = val;
  }

  Ajax.call('flow.php?step=change_surplus', 'surplus=' + val, changeSurplusResponse, 'GET', 'JSON');
}

/* *
 * 改变余额回调函数
 */
function changeSurplusResponse(obj)
{
  if (obj.error)
  {
    try
    {
      document.getElementById("ECS_SURPLUS_NOTICE").innerHTML = obj.error;
      document.getElementById('ECS_SURPLUS').value = '0';
      document.getElementById('ECS_SURPLUS').focus();
    }
    catch (ex) { }
  }
  else
  {
    try
    {
      document.getElementById("ECS_SURPLUS_NOTICE").innerHTML = '';
    }
    catch (ex) { }
    orderSelectedResponse(obj.content);
  }
}


//wwzedit 积分加减按钮切换
function checkIntegral()
{	
	$("#integralInfo").toggle();
	checkBenefitInfoText();
	
 	// var val = $("#integralCheckbox").attr('checked');
	// if (val === "checked")
	// {
		// //alert("yes");
		// $("#integralInfo").show();
	// }
	// else
	// {
		// $("#integralInfo").hide();
		// $("#ECS_INTEGRAL").val(0);
		// changeIntegral();
	// }  
}

/* *
 * 改变积分
 */
function changeIntegral()
{
  
  val = $("#ECS_INTEGRAL").attr("value");

  if(val!='')
  {
	  var reg=/^\d+$/g; //只能是数字
	  if(reg.test(val)==false)
	  {

		  $("#tips_big_div").show();
		  $("#tips_word").html("积分只能是数字");
		  //return;  
	  }else
	  {
		  if(val%100!=0)
		  {

			  $("#tips_big_div").show();
			  $("#tips_word").html("使用的积分只能是100的倍数");
			  //return;
			  
		  }else
		  {

			  
			  Ajax.call('flow.php?step=change_integral', 'points=' + val, changeIntegralResponse, 'GET', 'JSON');
			  
		  }
		  
	  }
	  
	  
  }else
  {
	  $("#tips_big_div").show();
	  $("#tips_word").html("积分不能为空");
	  //return;
  }
  
  // if (selectedIntegral == val)
  // {
    // return;
  // }
  // else
  // {
    // selectedIntegral = val;
  // }

  //Ajax.call('flow.php?step=change_integral', 'points=' + val, changeIntegralResponse, 'GET', 'JSON');
}

/* *
 * 改变积分回调函数
 */
function changeIntegralResponse(obj)
{
  if (obj.error)
  {
	$("#integralRight").val("0");
    try
    {
      document.getElementById('ECS_INTEGRAL_NOTICE').innerHTML = obj.error;
      document.getElementById('ECS_INTEGRAL').value = $("#chosenIntegral").val();
      document.getElementById('ECS_INTEGRAL').focus();
	  $("#tips_big_div").show();
	  $("#tips_word").html(obj.error);
	   
    }
    catch (ex) { }
  }
  else
  {

    try
    {
      document.getElementById('ECS_INTEGRAL_NOTICE').innerHTML = '';
    }
    catch (ex) { }

    $("#integralInfo").toggle();

    orderSelectedResponse(obj);
  }
}

//wwzedit 激活优惠券
function activateBonus()
{
	var bonus=document.getElementsByName('bonus_sn')[0].value;
	var captcha=document.getElementsByName('bonus_captcha')[0].value;
  $("#bonus_captcha,#bonus_sn").val('');
	if(bonus!='')
    {
		   var reg= /^[0-9a-zA-Z]{1,50}$/g;  //优惠券卡号
		   if(reg.test(bonus)==false)
		   {
				$("#tips_big_div").show();
				$("#tips_word").html("优惠券卡号格式不正确");
				return false;
			}else
			{
				if(captcha!='')
				{
					   var reg=/[0-9a-zA-Z]{4}/g;  //验证码验证只能4位数字和字母的组合
					   if(reg.test(captcha)==false)
					   {
							$("#tips_big_div").show();
							$("#tips_word").html("验证码的格式不正确");
							return false;
						}
				}else
				{
					$("#tips_big_div").show();
					$("#tips_word").html("验证码是空的");
					return false;
				}
			}
    }else
    {
    	$("#tips_big_div").show();
		$("#tips_word").html("优惠券卡号不能为空");
		return false;    	
    }
  
	Ajax.call('flow.php?step=activate_bonus', 'bonus_sn='+bonus+'&captcha='+captcha,activateBonusResponse,"POST","JSON");
}

//wwzedit 激活优惠券回调函数

function activateBonusResponse(result)
{
	$("#tips_big_div").show();
	$("#tips_word").html(result.content);
	$("#bonus_image_captcha").attr({src:'captcha.php?captcha_activate=1&'+Math.random()})
  if(result.error == 1) return false;
	try
	{
		var layer = document.getElementById("flow_bonus_list");
		layer.innerHTML = (typeof result == "object") ? result.html : result;
	}
 	catch (ex) { }
} 

//wwzedit 礼品卡激活
function activateGiftcard()
{
	var bonus=document.getElementsByName('giftcard_sn')[0].value;
	var captcha=document.getElementsByName('giftcard_captcha')[0].value;
	if(bonus!='')
    {
		   var reg= /^[0-9a-zA-Z]{1,50}$/g;  //优惠券卡号
		   if(reg.test(bonus)==false)
		   {
				$("#tips_big_div").show();
				$("#tips_word").html("礼品卡卡号格式不正确");
				return false;
			}else
			{
				if(captcha!='')
				{
					   var reg=/[0-9a-zA-Z]{4}/g;  //验证码验证只能4位数字和字母的组合
					   if(reg.test(captcha)==false)
					   {
							$("#tips_big_div").show();
							$("#tips_word").html("验证码的格式不正确");
							return false;
						}
				}else
				{
					$("#tips_big_div").show();
					$("#tips_word").html("验证码是空的");
					return false;
				}
			}
    }else
    {
    	$("#tips_big_div").show();
  		$("#tips_word").html("礼品卡卡号不能为空");
  		return false;
    }
	Ajax.call('flow.php?step=activate_giftcard', 'bonus_sn='+bonus+'&captcha='+captcha,activateGiftcardResponse,"POST","JSON");
}

//wwzedit 激活礼品卡回调函数

function activateGiftcardResponse(result)
{
	$("#tips_big_div").show();
	$("#tips_word").html(result.content);

  $("#giftcard_image_captcha").attr({src:'captcha.php?captcha_activate=1&'+Math.random()})
  $("#giftcard_captcha,#giftcard_sn").val('');
  if(result.error == 1) return false;
	try
	{
		var layer = document.getElementById("flow_giftcard_list");
		layer.innerHTML = (typeof result == "object") ? result.html : result;
	}
 	catch (ex) { }
} 


/* *
 * 改变红包
 */
function changeBonus()
{
    val = $("#ECS_BONUS").find("option:selected").val();
    $("#couponInfo").hide();
    Ajax.call('flow.php?step=change_bonus', 'bonus=' + val, changeBonusResponse, 'GET', 'JSON');
  

}

/* *
 * 改变红包的回调函数
 */
function changeBonusResponse(obj)
{
  if (obj.error)
  {
    alert(obj.error);

    try
    {
      document.getElementById('ECS_BONUS').value = '0';
    }
    catch (ex) { }
  }
  else
  {

    orderSelectedResponse(obj);
  }
}

//var giftcardFull = "0";

//wwzedit 检查积分卡选中情况
function checkGiftcard(){
    var giftcardMoney = 0;
    var goods_price = parseInt( $("#goods_price_hidden").val() ); 
    var shipping_fee = parseInt( $("#shipping_fee_hidden").val() );
    
    var goodspricePlusShippingfee = goods_price + shipping_fee;
    
    $("input:checkbox[name='giftcardID'][checked]").each(function(){
        giftcardMoney = giftcardMoney + parseInt( $(this).attr("value2") );
    });
    
    if ( $("input:checkbox[name='giftcardID']").length > 1 )
    {
        if (giftcardMoney >= goodspricePlusShippingfee){
            $("input:checkbox[name='giftcardID']").not("[checked]").each(function(){
                $(this)[0].disabled = true ;
            });        
        }else{
            $("input:checkbox[name='giftcardID']").not("[checked]").each(function(){
                $(this)[0].disabled = false ;
            });
        }
    }

    

// for(var i=0;i<giftcard.giftcardID.length;i++) 
// {
	// if(giftcardFull === "0")
	// {
		// giftcard.giftcardID[i].disabled = false;
	// }
	// else if (giftcard.giftcardID[i].checked === false && giftcardFull === "1")
	// {
		// giftcard.giftcardID[i].disabled = true;
	// }	
// } 

// var temp="";
// for(var i=0;i<giftcard.giftcardID.length;i++) 
// {
	// if (giftcard.giftcardID[i].checked) 
	// {
		// temp= temp+giftcard.giftcardID[i].value;
		// temp = temp + ",";
	// }
// }
// Ajax.call('flow.php?step=change_giftcard', 'giftcard=' + temp, changeGiftcardResponse, 'GET', 'JSON'); 
}

function changeGiftcard()
{
	var giftCardId = new Array();
    $("input:checkbox[name='giftcardID[]'][checked]").each(function(){
        giftCardId.push($(this).val());

    });

    Ajax.call('flow.php?step=change_giftcard', 'giftcardId='+giftCardId, changeGiftcardResponse, 'POST', 'JSON');
}

/* *
 * 改变礼品卡的回调函数
 */
function changeGiftcardResponse(obj)
{
  
  if (obj.error)
  {
    alert(obj.error);

    try
    {
      document.getElementById('ECS_BONUS').value = '0';
    }
    catch (ex) { }
  }
  else
  {
    $("input:checkbox[name='giftcardID[]']").each(function(){

        if($(this).is(":checked")){
          $(this).parent().siblings('.use_status').html('<span class="in_used">已使用</span>');  
        }else{
          $(this).parent().siblings('.use_status').html('<span class="not_use">未使用</span>');  
        }

        
    });
    $("#giftcard_info").hide();
    orderSelectedResponse(obj);
    
  }
}


/**
 * 验证红包序列号
 * @param string bonusSn 红包序列号
 */
function validateBonus(bonusSn)
{
  Ajax.call('flow.php?step=validate_bonus', 'bonus_sn=' + bonusSn, validateBonusResponse, 'GET', 'JSON');
}

function validateBonusResponse(obj)
{

if (obj.error)
  {
    alert(obj.error);
    orderSelectedResponse(obj.content);
    try
    {
      document.getElementById('ECS_BONUSN').value = '0';
    }
    catch (ex) { }
  }
  else
  {
    orderSelectedResponse(obj.content);
  }
}

/* *
 * 改变发票的方式
 */
function changeNeedInv()
{
  var obj        = document.getElementById('ECS_NEEDINV');
  var objType    = document.getElementById('ECS_INVTYPE');
  var objPayee   = document.getElementById('ECS_INVPAYEE');
  var objContent = document.getElementById('ECS_INVCONTENT');
  var needInv    = obj.checked ? 1 : 0;
  var invType    = obj.checked ? (objType != undefined ? objType.value : '') : '';
  var invPayee   = obj.checked ? objPayee.value : '';
  var invContent = obj.checked ? objContent.value : '';
  objType.disabled = objPayee.disabled = objContent.disabled = ! obj.checked;
  if(objType != null)
  {
    objType.disabled = ! obj.checked;
  }

  Ajax.call('flow.php?step=change_needinv', 'need_inv=' + needInv + '&inv_type=' + encodeURIComponent(invType) + '&inv_payee=' + encodeURIComponent(invPayee) + '&inv_content=' + encodeURIComponent(invContent), orderSelectedResponse, 'GET');
}

/* *
 * 改变发票的方式
 */
function groupBuyChangeNeedInv()
{
  var obj        = document.getElementById('ECS_NEEDINV');
  var objPayee   = document.getElementById('ECS_INVPAYEE');
  var objContent = document.getElementById('ECS_INVCONTENT');
  var needInv    = obj.checked ? 1 : 0;
  var invPayee   = obj.checked ? objPayee.value : '';
  var invContent = obj.checked ? objContent.value : '';
  objPayee.disabled = objContent.disabled = ! obj.checked;

  Ajax.call('group_buy.php?act=change_needinv', 'need_idv=' + needInv + '&amp;payee=' + invPayee + '&amp;content=' + invContent, null, 'GET');
}

/* *
 * 改变缺货处理时的处理方式
 */
function changeOOS(obj)
{
  if (selectedOOS == obj)
  {
    return;
  }
  else
  {
    selectedOOS = obj;
  }

  Ajax.call('flow.php?step=change_oos', 'oos=' + obj.value, null, 'GET');
}

//wwzedit 检查订单
function checkOrderFormWWZ()
{
    if(confirmAddress == false){
        showMsg('请先确认收货地址');
        return false;
    }
    if(confirmShippingTime == false){
        showMsg('请先确认配送时间');
        return false;
    }
    if(confirmCoupon == false){
        showMsg('请先确认优惠信息');
        return false;
    }
    if(confirmInvoice == false){
        showMsg('请先确认发票信息');
        return false;
    }
    if(confirmPayment == false){
        showMsg('请先确认支付方式');
        return false;
    }


	var invoice = confirmInvoiceInfo();
	//var val = $("[name=consignee_list]").attr("checked") ;

	var val = $('input[name="consignee_list"]:checked').val();
	var payment = $('input[name="payment"]:checked').val();
	if(invoice === true)

    {
        if( val > 0 )
        {	
            if ( mobile_confirm === "1" || payment > 1)
            {
                $("#theForm").submit();
				        setCookie('temp_user_consignee','',0);
            }
            else
            {
				        $('#mobile_confirm_window').show();
                showMsg('请验证手机。')
            }
        }
        else
        {
            showMsg('请检查收货地址。');
        }
    }
}

/* *
 * 检查提交的订单表单
 */
function checkOrderForm(frm)
{
  var paymentSelected = false;
  var shippingSelected = false;

  // 检查是否选择了支付配送方式
  for (i = 0; i < frm.elements.length; i ++ )
  {
    if (frm.elements[i].name == 'shipping' && frm.elements[i].checked)
    {
      shippingSelected = true;
    }

    if (frm.elements[i].name == 'payment' && frm.elements[i].checked)
    {
      paymentSelected = true;
    }
  }

  if ( ! shippingSelected)
  {
    alert(flow_no_shipping);
    return false;
  }

  if ( ! paymentSelected)
  {
    alert(flow_no_payment);
    return false;
  }

  // 检查用户输入的余额
  if (document.getElementById("ECS_SURPLUS"))
  {
    var surplus = document.getElementById("ECS_SURPLUS").value;
    var error   = Utils.trim(Ajax.call('flow.php?step=check_surplus', 'surplus=' + surplus, null, 'GET', 'TEXT', false));

    if (error)
    {
      try
      {
        document.getElementById("ECS_SURPLUS_NOTICE").innerHTML = error;
      }
      catch (ex)
      {
      }
      return false;
    }
  }

  // 检查用户输入的积分
  if (document.getElementById("ECS_INTEGRAL"))
  {
    var integral = document.getElementById("ECS_INTEGRAL").value;
    var error    = Utils.trim(Ajax.call('flow.php?step=check_integral', 'integral=' + integral, null, 'GET', 'TEXT', false));

    if (error)
    {
      return false;
      try
      {
        document.getElementById("ECS_INTEGRAL_NOTICE").innerHTML = error;
      }
      catch (ex)
      {
      }
    }
  }
  frm.action = frm.action + '?step=done';
  return true;
}

/* *
 * 检查收货地址信息表单中填写的内容
 */
function checkConsignee(frm)
{
	
  //var msg = new Array();
 // var err = false;

  /*
  if (frm.elements['country'] && frm.elements['country'].value == 0)
  {
    msg.push(country_not_null);
    err = true;
  }

  if (frm.elements['province'] && frm.elements['province'].value == 0 && frm.elements['province'].length > 1)
  {
    err = true;
    msg.push(province_not_null);
  }

  if (frm.elements['city'] && frm.elements['city'].value == 0 && frm.elements['city'].length > 1)
  {
    err = true;
    msg.push(city_not_null);
  }
  */
  
 /* if (frm.elements['district'] && frm.elements['district'].length > 1)
  {
    if (frm.elements['district'].value == 0)
    {

      err = true;
      msg.push(district_not_null);
    }
  }*/
  
  var consignee=document.theForm.consignee.value;
  var address=document.theForm.address.value;
  var mobile=document.theForm.mobile.value;
  
  if(consignee!='')
	{
			 var reg=/^([\w\u4e00-\u9fa5]{1,20})$/g; 
			   if(reg.test(consignee)==false)
			   {
					showMsg('姓名的格式不正确');
					return false;
				}else{
				 	if(address!='')
					{
					    	if(mobile!='')
							{
							 	   var reg= /^1[3458]\d{9}$/g;  //手机号码的验证 11位，
								   if(reg.test(mobile)==false)
								   {
									  showMsg('手机的格式不正确');
										return false;
										
									}
							}else
							{
							  showMsg('手机号不能为空')
								return false;
							}
					
					}else
					{
						showMsg('地址不能为空');
						return false;
					
					
					}
				}	
				
				
	} else
	{
		showMsg('姓名不能为空');
		return false;
	
	}

  
 /* if (Utils.isEmpty(frm.elements['consignee'].value))
  {

    err = true;
    msg.push(consignee_not_null);
  }

  if (Utils.isEmpty(frm.elements['address'].value))
  {

    err = true;
    msg.push(address_not_null);
  }


  

  if (frm.elements['mobile'] && 
		((frm.elements['mobile'].value.length > 0 && (!Utils.isTel(frm.elements['mobile'].value))) 
			|| frm.elements['mobile'].value.length==0 ))
  {
    err = true;
    msg.push(mobile_invaild);
  }

  if (err)
  {

    message = msg.join("\n");
    alert(message);
  }*/
 
  //return ! err;
}
